import java.util.*;

public class Gloves {
    public int findMinimum(int n, int[] left, int[] right) {
        // write code here
        int a=0;
        int b=0;
        int num=0;
        int x=0;
        int y=0;
        int leftMax=Integer.MAX_VALUE;
        int rightMax=Integer.MAX_VALUE;
        for (int i = 0; i < n; i++) {
            if(left[i]==0){
                y+=right[i];
             right[i]=0;
            }
            if(right[i]==0){
                x+=left[i];
                left[i]=0;
            }
            if(left[i]!=0){
                num++;
                leftMax=Math.max(leftMax,left[i]);
                rightMax=Math.max(rightMax,right[i]);
            }
            a+=left[i];
            b+=right[i];
        }
       return Math.min((y+rightMax+1+x+1),(x+leftMax+1+y+1));
    }
}